/*
*    UNIVERSIDADE DE SÃO PAULO.
*    Author: Marco Aurélio Gerosa (gerosa@ime.usp.br)
*
*    This file is part of Groupware Workbench (http://www.groupwareworkbench.org.br).
*
*    Groupware Workbench is free software: you can redistribute it and/or modify
*    it under the terms of the GNU Lesser General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    Groupware Workbench is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU Lesser General Public License for more details.
*
*    You should have received a copy of the GNU Lesser General Public License
*    along with Swift.  If not, see <http://www.gnu.org/licenses/>.
*/
package br.org.groupwareworkbench.collablet.coop.recommend;

import java.util.ArrayList;
import java.util.List;

// TODO: ISTO É UM COPY-PASTE DA CLASSE TagUtil.
// TODO: Excluir os métodos inúteis e unificar os que forem úteis em uma só classe.
public final class RecommendUtil {

    private RecommendUtil() {}

    /* Remover caracteres que não são do alfabeto */
    public static String removeChars(String texto) {
        texto = texto.replaceAll("([^a-zA-z,])", " ");
        return texto;
    }

    public static String normalizacao(String texto) {
        texto = texto.toLowerCase();
        return texto;
    }

    // TODO: Este método é chamado em algum lugar? Se não for eliminá-lo.
    // Se for, otimizá-lo e excluir a concatenação de Strings dentro dele (encontrado pelo FindBugs).
    public static String recommendsToString(String... recommends) {
        String toReturn = "";
        for (String recommendName : recommends) {
            recommendName = recommendName.replaceAll(" ", "");
            if (!"".equals(recommendName) && !toReturn.contains(recommendName)) {
                toReturn += "," + recommendName;
            }
        }
        return toReturn.substring(1);
    }

    public static List<String> stringToRecommends(String string) {
        List<String> toReturn = new ArrayList<String>();

        /*
         * string = StringConverter.deleteAcentos(string); string = removeChars(string); string = normalizacao(string);
         */
        String[] recommends = string.split(",");
        for (String recommend : recommends) {
            if (!recommend.trim().isEmpty()) {
                toReturn.add(recommend.trim());
            }
        }
        return toReturn;
    }
}
